export default{
	common:{
		baseUrl:'http://www.creb.com.cn/api/front/mobile',
		method:"GET",
		header:{
			'Content-Type':'application/json;charset=UTF-8',
			'Content-Type':'application/x-www-form-urlencoded'
		},
		data:{},
		dataType:'json'
	},
	request(options={}){
		let token = uni.getStorageSync('token');
		let cityLocation = uni.getStorageSync('location');
		let siteId = cityLocation ? JSON.parse(cityLocation).id : 1;
		options.url = options.coverUrl || (this.common.baseUrl + options.url);
		options.method = options.method || this.common.method;
		options.dataType = options.dataType || this.common.dataType;
		options.header = options.header || this.common.header;
		options.data = options.data || this.common.data;
		options.data.token = token;
    options.data.siteId = siteId;

		console.log('token', token)

		return new Promise((res,rej) => {
			uni.request({
				...options,
				success: response => {
					if(response.statusCode === 200){
						if(response.data.code == 200){
							let dataset = response.data.body;
							res(dataset)
						}else{
							uni.showToast({
								title: response.data.message
							})
							res()
						}
					} else {
						console.error('REQUEST ERR: ', options.url, response)
						uni.showToast({
							title: '服务器请求出错!'
						});
						rej(response)
					}
				},
				fail: (err) => {
					console.error('uni.request fail', err)
					uni.showToast({
						title: err.errMsg
					})
					return rej(err)
				}
			})
		})
	}
}